package com.chapter10.static_.case_static;

public class VisitStatic {
    public static void main(String[] args) {

        //类名访问
        System.out.println(A.name);

        //对象访问
        A a = new A();
        System.out.println(a.name);
        System.out.println(new A().name);

        //遵循访问权限规则
//        System.out.println(new A().address);  报错

        //在类加载的时候就可以访问静态属性
        System.out.println(B.Weight);


        //静态方法在开发工具的时候节省时间，也在写代码时提高效率
        System.out.println(MyTools.calc(2,3));

        System.out.printf(""+Math.sqrt(4.0));

        /*
        * 静态方法只能访问静态成员。
        * 静态方法不允许使用和对象有关的关键字
        * 非静态方法既能访问静态成员，也能访问非静态成员
        * */

    }
}

class Test{
    private String name;
    public static int Weight;

    public void m1(){
        System.out.println(name);
        System.out.println(Weight);
        m3(1);
        m4();
        System.out.println("m1");
    }

    //非静态方法既能访问静态成员，也能访问非静态成员
    public void m4(){
        System.out.println("m4");
    }

    //静态方法只能访问静态成员。
    public static void m2(){
        System.out.println(Weight);
        m3(2);
    }


    //静态方法不允许使用和对象有关的关键字
    public static void m3(int weight){
//        this.Weight = weight;
        System.out.println("m3");

    }

}


class MyTools{

    public static double calc(int a, int b){
        return a*b;
    }
}



class A {
    public static String name = "Tom";
    private static String address = "Beijing";

}
class B {
    public static Double Weight = 70.0;
}
